package com.fengmi.mapper;

import com.fengmi.entity.StatOrder;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Author: 施俊豪
 * Date: 2022/2/8 14:35
 * Note: 订单mapper层接口
 */
public interface OrderStatMapper {

    // 查询每日前一天的订单统计情况
    @Select("SELECT\n" +
            "\tDATE_FORMAT( create_time, '%Y-%m-%d' ) as sta_dat,\n" +
            "\tsum( pay_amount ) AS sta_amount,count(*) AS sta_cunt \n" +
            "FROM oms_order WHERE\n" +
            "DATE_FORMAT( create_time, '%Y-%m-%d' ) = DATE_SUB(CURDATE(),INTERVAL 1 DAY)")
    public StatOrder findOrderByDay();

    // 添加每日的订单统计情况
    @Insert("insert into stat_order(sta_dat,sta_amount,sta_cunt) values(#{staDat},#{staAmount},#{staCunt})")
    public Integer insertStatOrderByDay(StatOrder statOrder);

    // 按日期查询订单统计
    public List<StatOrder> findOrderByTime(@Param("startTime") String startTime, @Param("endTime")String endTime);
}
